﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using WinHBM.Core.Net.Http;

namespace WinHBM.Core.Net.Sockets.Cmd
{
    public class GetBarCodeCmd : SocketCmd
    {
        private HttpClient httpClient = HttpClient.Instance;
        public override void executeCmd(JObject request, FlashSocketServer socket)
        {
            httpClient.CreateRequest("/api/user-role/bar-code",RequestMethod.POST).send((respnse, data) => {
                JObject ret = new JObject();
                ret["address"] = data["contents"]["code"].ToString();
                //更新UserInfo
                UserInfo user = UserInfo.INSTANCE;
                user.Address = data["contents"]["code"].ToString();
                user.commit();
                socket.Send(wrapCmd(CMD_GETBARCODE, ret));
            },(response,exception)=> {
                socket.Send(wrapCmd(CMD_GETBARCODE, "请求失败"));
            });
        }
    }
}
